#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve()
{
    string s;
    cin >> s;
    map<string, int> mp;
    vector<int> h;
    for (auto e : s)
    {
        if (e == 'c' || e == 'z')
        {
            string t(1, e);
            mp[t]++;
        }
        else if (e == 'f') mp["cf"] += mp["c"];
        else if (e == 'y') mp["zy"] += mp["z"];
        h.push_back(mp["cf"] - mp["zy"]);
    }
    int ans = *min_element(h.begin(), h.end());
    if (ans >= 0) cout << "YES" << endl;
    else cout << "NO" << endl << -ans << endl;
    //     if(h >= 0) cout << "YES" << endl;
    //     else cout << "NO" << endl << -h << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}